<html>
    <body>
        <input type="checkbox" id="1">
        <input type="checkbox" id="2">
        <input type="checkbox" id="3">
        <input type="checkbox" id="4">
        <input type="checkbox" id="5">
        <input type="checkbox" id="6">
        <input type="checkbox" id="7">
        <input type="checkbox" id="8">
        <input type="checkbox" id="9">
        <input type="checkbox" id="10">
    </body>

    <script>
        var synchronousFile = function(id) {
            console.log('已同步文件'+ id);
        }

        var proxySynchronousFile = (function() {
            var cache = [];
            var timer;

            return function(id) {
                cache.push(id);
                if (timer) return;
                timer = setTimeout(() => {
                    synchronousFile(cache.join(','));
                    clearTimeout(timer);
                    timer = null;
                    cache.length = 0;
                }, 2000)
            }
        })();

        var checkbox = document.getElementsByTagName('input');
        for (var i = 0, c; c = checkbox[i++]; ) {
            c.onclick = function() {
                if (this.checked) {
                    synchronousFile(this.id)
                }
            }
        }
    </script>
</html>